﻿using System.Collections.Generic;
using LFloatMath.Math;

namespace IQIGame.Onigao.GamePlay
{
    public class AttributeViewComponent : TComponent
    {
        public AttributeProperty attr;
        public UnitView unit { get; private set; }

        protected override void OnDispose()
        {
        }

        public void Initialize(List<int> rAttr)
        {
            this.attr.Initialize(rAttr, this.unit.lv);
        }
        
        public override void OnCreate(TEntity entity)
        {
            this.unit = entity as UnitView;
            this.attr = new AttributeProperty();
        }

        public LFloat Get(EAttributeType rType)
        {
            return this.attr.Get(rType);
        }

        public void Set(EAttributeType rType, int nValue, EAttributeAddType rAddType = EAttributeAddType.Base)
        {
            this.attr.Set(rType, nValue, rAddType);
        }

        public void Add(EAttributeType rType, int nValue, EAttributeAddType rAddType = EAttributeAddType.Add)
        {
            switch (rAddType)
            {
                case EAttributeAddType.Add:
                    this.attr.Add(rType, nValue);
                    break;
                case EAttributeAddType.Percent:
                    this.attr.AddPercent(rType, nValue);
                    break;
            }
        }
        
        public int GetPanel(EAttributeType rType)
        {
            return this.attr.GetAll(rType).Item1;
        }
    }
}